import http from '../../utils/http.js';
import apiConfig from '../../utils/apiConfig.js';
Page({
  data: {
    // 分页参数
    currentPage: 1,
    totalPage: 1,
    manufacturerList: [],
    isLoading: false
  },
  onLoad() {
    this.getManufacturerList();
  },
  getManufacturerList() {
    const that = this;
    this.setData({ isLoading: true });
    http.request({
      url: apiConfig.getManufacturerList,
      method: 'GET',
      data: {
        page: this.data.currentPage,
      }
    }).then((res) => {
      const data = res.data;
      that.setData({
        currentPage: data.current_page,
        totalPage: data.last_page,
        manufacturerList: data.data,
        isLoading: false
      });
    }).catch((err) => {
      console.error('请求失败', err);
      that.setData({ isLoading: false });
    });
  },
  onReachBottom() {
    const that = this;
    if (that.data.currentPage < that.data.totalPage) {
      that.setData({
        currentPage: that.data.currentPage + 1
      }, () => {
        that.getManufacturerList();
      });
    }
  },
  gotoPage(e) {
    const url = e.currentTarget.dataset.url;
    wx.navigateTo({ url })
  }
})